<?php

defined('_JEXEC') or die;

jimport('joomla.application.component.controllerform');

class ExercisesControllerResult extends JControllerForm {

    public function save($key = null, $urlVar = null) {
        JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
        $data = JRequest::getVar('jform', array());
        if ($data['id']) {
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->update($db->quoteName('#__exercises_results'))
                    ->set($db->quoteName('status') . ' = ' . (int) $data['status'])
                    ->where('id = ' . (int) $data['id']);
            $db->setQuery($query);
            $db->query();
        }
        $this->setRedirect(JRoute::_('index.php?option=com_exercises&view=results', false));
        return true;
    }

}
